package com.tuanzi.loan.business.service.family.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tuanzi.loan.business.repository.family.UserMobileExportRepository;
import com.tuanzi.loan.business.service.family.UserMobileExportService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.exception.ValidateException;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.family.UserMobileExportSearchRequest;
import com.tuanzi.loan.vo.response.family.UserMobileExportSearchResponse;
/**
 * 
 * @author Xumiaohang 2017/11/13
 *
 */
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class UserMobileExportServiceImpl implements UserMobileExportService {

	@Autowired
	private UserMobileExportRepository userMobileExportRepository;
	
	private PageSearcher<UserMobileExportSearchRequest> pageSearcher;

	@Override
	public Page<UserMobileExportSearchResponse> list(
			PageSearcher<UserMobileExportSearchRequest> pageSearcher) {
		
		this.pageSearcher=pageSearcher;
		return userMobileExportRepository.list(
				pageSearcher.getSearchCondition(), pageSearcher.getPageable());
	}

	@Override
	public void onCheck() {
		//查询注册用户
		if ("0".equals(pageSearcher.getSearchCondition().getUserType())) {
			if (pageSearcher.getSearchCondition().getStartRegTime() == null
					|| pageSearcher.getSearchCondition().getEndRegTime() == null) {
				throw new ValidateException("请输入注册的开始和结束时间");
			}
			
		//查询登记未注册用户	
		}else if("1".equals(pageSearcher.getSearchCondition().getUserType())){
			if(pageSearcher.getSearchCondition().getStartRecTime()==null 
					|| pageSearcher.getSearchCondition().getEndRecTime()==null){
				throw new ValidateException("请输入登记的开始和结束时间");
			}
		}

	}
	
	//获取需要导出的数据
	@Override
	public List<UserMobileExportSearchResponse> getExportData(
			UserMobileExportSearchRequest searchRequest, int offset,
			int pageSize) {
		return userMobileExportRepository.getExportData(searchRequest, offset, pageSize);
	}

}
